package com.sundaying.gooway.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import com.sundaying.gooway.model.UrlClass;
import com.sundaying.gooway.model.UrlItem;
import com.sundaying.gooway.service.UrlClassService;
import com.sundaying.gooway.service.UrlItemService;

;

public class UrlItemAction extends ActionSupport {
	private UrlItemService urlItemService = new UrlItemService();
	private UrlClassService urlClassService = new UrlClassService();
	// 网址对象
	private UrlItem urlItem;
	// 网址集合对象
	private List<UrlItem> urlItemList;
	// 网址ID
	private int itemID;

	private List<UrlClass> urlClassList;

	// 视图datagrid属性
	private int page;
	private int rows;
	private int total;
	private Map<String, Object> urlItemMap;
	private String urlClassID;

	public String getUrlClassID() {
		return urlClassID;
	}

	public void setUrlClassID(String urlClassID) {
		this.urlClassID = urlClassID;
	}

	public Map<String, Object> getUrlItemMap() {
		return urlItemMap;
	}

	public void setUrlItemMap(Map<String, Object> urlItemMap) {
		this.urlItemMap = urlItemMap;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public List<UrlClass> getUrlClassList() {
		return urlClassList;
	}

	public void setUrlClassList(List<UrlClass> urlClassList) {
		this.urlClassList = urlClassList;
	}

	public int getItemID() {
		return itemID;
	}

	public void setItemID(int itemID) {
		this.itemID = itemID;
	}

	public UrlItem getUrlItem() {
		return urlItem;
	}

	public List<UrlItem> getUrlItems() {
		return urlItemList;
	}

	public void setUrlItems(List<UrlItem> urlItems) {
		this.urlItemList = urlItems;
	}

	public void setUrlItem(UrlItem urlItem) {
		this.urlItem = urlItem;
	}

	public String init() {
		urlClassList = urlClassService.list();
		return this.SUCCESS;
	}

	/*
	 * 添加网址
	 */
	public String add() {
		urlItemService.add(urlItem);
		return this.SUCCESS;
	}

	/*
	 * 获取所有网址
	 */
	public String list() {
		if (this.getUrlClassID() == null || this.getUrlClassID().trim().equals("")) {
			urlItemList = urlItemService.list(page, rows);
			total = urlItemService.getCount();
			urlItemMap = new HashMap<String, Object>();
			urlItemMap.put("total", total);
			urlItemMap.put("rows", urlItemList);
			System.out.println("默认查询记录：" + urlItemList.size());
		} else {
			urlItemList = urlItemService.list(page, rows, this.getUrlClassID());
			total = urlItemService.getCount();
			urlItemMap = new HashMap<String, Object>();
			urlItemMap.put("total", total);
			urlItemMap.put("rows", urlItemList);
			System.out.println("查询记录：" + urlItemList.size());
		}
		return this.SUCCESS;
	}

	public List<UrlItem> getUrlItemList() {
		return urlItemList;
	}

	public void setUrlItemList(List<UrlItem> urlItemList) {
		this.urlItemList = urlItemList;
	}

	public String delete() {
		urlItemService.delete(itemID);
		return this.SUCCESS;
	}

	public String loadById() {
		urlClassList = urlClassService.list();
		urlItem = urlItemService.loadByID(itemID);
		return this.SUCCESS;
	}

	public String update() {
		urlItemService.update(urlItem);
		return this.SUCCESS;
	}

}
